import {
    a as createElementBlock,
    ae as vModelRadio,
    af as useUrlSearchParams,
    b as createBaseVNode,
    c as createBlock,
    d as defineComponent,
    e as ref,
    E as withKeys,
    F as Fragment,
    G as api,
    J as mergeModels,
    j as renderList,
    k as createCommentVNode,
    K as onMounted,
    L as withDirectives,
    m as useModel,
    n as normalizeClass,
    O as resolveDynamicComponent,
    o as openBlock,
    p as withCtx,
    q as createVNode,
    s as _sfc_main$6,
    t as toDisplayString,
    u as unref,
    v as createTextVNode,
    w as watch,
    y as isRef
} from "./index-Dfdf_Rjk.js";
import {_ as _sfc_main$b} from "./SimpleDialog.vue_vue_type_script_setup_true_lang-B70uDCdu.js";
import {
    _ as _sfc_main$a,
    a as getExecutorList,
    b as getExecutorProgramList,
    c as createExecutorJar,
    d as createExecutorProgram,
    e as deleteExecutorProgram
} from "./executor-Csm15pJV.js";
import {_ as _sfc_main$9} from "./SimpleInput.vue_vue_type_script_setup_true_lang-D6HMgtcH.js";
import {
    _ as _sfc_main$c,
    a as _sfc_main$8,
    b as _sfc_main$7
} from "./SimpleCollapse.vue_vue_type_script_setup_true_lang-rzMMFhj6.js";
import {_ as _sfc_main$5} from "./IconButton.vue_vue_type_script_setup_true_lang-jAwwuJ2U.js";
import {
    b as getAllTags,
    e as getDataBasesByPage,
    h as getDataBasePatterns,
    i as createDataBaseSource,
    j as updateDataBaseSource,
    k as createTag,
    l as deleteTag
} from "./model-CGDRSQW4.js";

const _hoisted_1$4 = ["disabled"];
const _hoisted_2$4 = {key: 2};
const _hoisted_3$3 = ["disabled", "value"];
const _sfc_main$4 = /* @__PURE__ */ defineComponent({
    __name: "SimpleTabs",
    props: /* @__PURE__ */ mergeModels({
        blocked: {type: Boolean},
        disabled: {type: Boolean},
        divide: {type: Boolean},
        vertical: {type: Boolean},
        options: {}
    }, {
        "modelValue": {},
        "modelModifiers": {}
    }),
    emits: ["update:modelValue"],
    setup(__props) {
        const input = useModel(__props, "modelValue");
        return (_ctx, _cache) => {
            return openBlock(), createElementBlock("fieldset", {
                class: normalizeClass(["flex-inline bg-base", [
                    _ctx.divide ? "" : "p-0.2em gap-1",
                    _ctx.blocked ? "w-full" : "",
                    _ctx.vertical ? "flex-col !gap-2 !p-0" : "border border-base rounded items-center flex-wrap"
                ]])
            }, [
                (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.options, (i, idx) => {
                    return openBlock(), createElementBlock("label", {
                        key: idx,
                        disabled: i.disabled,
                        class: normalizeClass(["relative flex flex-nowrap cursor-pointer items-center border-base hover:bg-hover px-2 py-1", [
                            _ctx.divide && idx ? "border-l border-base ml--1px" : "",
                            _ctx.divide && idx === 0 ? "rounded-l" : "",
                            _ctx.divide && idx === _ctx.options.length - 1 ? "rounded-r" : "",
                            _ctx.divide ? "" : "rounded",
                            i.value === input.value ? " text-primary !bg-primary/15" : "",
                            i.disabled ? "disabled" : "",
                            _ctx.blocked ? "flex-1" : "",
                            _ctx.vertical ? "" : "justify-center",
                            i.class
                        ]])
                    }, [
                        createBaseVNode("div", {
                            class: normalizeClass([{
                                "op80": i.value !== input.value,
                                "w-full": _ctx.vertical
                            }, "flex items-center gap-1"])
                        }, [
                            i.icon ? (openBlock(), createElementBlock("div", {
                                key: 0,
                                class: normalizeClass(i.icon)
                            }, null, 2)) : createCommentVNode("", true),
                            typeof i.label === "function" ? (openBlock(), createBlock(resolveDynamicComponent(i.label()), {key: 1})) : (openBlock(), createElementBlock("span", _hoisted_2$4, toDisplayString(i.label), 1))
                        ], 2),
                        withDirectives(createBaseVNode("input", {
                            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => input.value = $event),
                            type: "radio",
                            disabled: i.disabled,
                            value: i.value,
                            class: "absolute inset-0 cursor-pointer op-0.1"
                        }, null, 8, _hoisted_3$3), [
                            [vModelRadio, input.value]
                        ])
                    ], 10, _hoisted_1$4);
                }), 128))
            ], 2);
        };
    }
});

function useUrlQuery(tabs, tabName = "tab") {
    const urlParams = useUrlSearchParams("history");
    const tabsRef = ref(tabs);

    function defaultTab() {
        const c = urlParams[tabName];
        if (c && tabsRef.value.find((u) => u.value === c)) {
            return c;
        }
        urlParams[tabName] = tabsRef.value[0].value;
        return tabsRef.value[0].value;
    }

    const activeTab = ref(defaultTab());
    watch(activeTab, (v) => {
        urlParams[tabName] = v;
    });
    return {
        activeTab
    };
}

const _hoisted_1$3 = {class: "flex flex-col gap-6 px-2"};
const _hoisted_2$3 = {class: "flex items-center gap-2"};
const _hoisted_3$2 = {
    key: 1,
    class: "flex flex-col gap-2"
};
const _hoisted_4$2 = {class: "flex flex-col gap-1"};
const _hoisted_5$2 = {class: "flex items-baseline gap-2"};
const _hoisted_6$2 = {class: "font-500"};
const _hoisted_7$1 = {class: "text-sm text-gray-600 font-[monaco]"};
const _hoisted_8$1 = {class: "text-sm text-gray-600"};
const _hoisted_9$1 = {class: "flex-center flex-none gap-3 text-sm"};
const _hoisted_10$1 = ["onClick"];
const _hoisted_11$1 = {
    key: 2,
    class: "flex-center"
};
const _hoisted_12$1 = {class: "p-6 text-1.2rem font-600"};
const _hoisted_13$1 = {class: "max-h-600px flex flex-col gap-3 overflow-y-overlay px-6 pb-6"};
const _hoisted_14$1 = {class: "form-group"};
const _hoisted_15$1 = {class: "w-full flex gap-6"};
const _hoisted_16$1 = {class: "form-group w-50%"};
const _hoisted_17$1 = ["value"];
const _hoisted_18$1 = {class: "form-group w-50%"};
const _hoisted_19$1 = ["value"];
const _hoisted_20$1 = {class: "form-group"};
const _hoisted_21$1 = {class: "w-full flex gap-6"};
const _hoisted_22$1 = {class: "form-group w-50%"};
const _hoisted_23$1 = {class: "form-group w-50%"};
const _hoisted_24$1 = {class: "form-group"};
const _hoisted_25$1 = {class: "form-group"};
const _hoisted_26 = {class: "form-group"};
const _hoisted_27 = {class: "form-group"};
const _hoisted_28 = {class: "form-group"};
const _hoisted_29 = {class: "form-group"};
const _hoisted_30 = {class: "form-group"};
const _hoisted_31 = {class: "flex justify-end gap-4 p-6"};
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
    __name: "index",
    setup(__props) {
        const typeClassMap = {
            dm: "purple-badge",
            clickhouse: "yellow-badge",
            mysql: "orange-badge",
            postgresql: "blue-badge",
            neo4j: "green-badge"
        };
        const flag = ref("create");
        const dataSources = ref([]);

        function initFormInfo() {
            return {
                rdbName: "",
                rwType: "",
                dbType: "",
                dbUrl: "",
                dbUserName: "",
                dbPassword: "",
                record: "",
                driverName: "",
                schemaName: "",
                clusterName: "",
                engine: ""
            };
        }

        const formInfo = ref(initFormInfo());
        const visible = ref(false);
        const loading = ref(false);
        const dbTypes = ref([]);
        const dbPatterns = ref({});

        function getPatterns() {
            getDataBasePatterns().then((res) => {
                dbPatterns.value = res.data;
                dbTypes.value = Object.keys(res.data);
            }).catch(() => {
                dbPatterns.value = {};
                dbTypes.value = [];
            });
        }

        function getData() {
            loading.value = true;
            getDataBasesByPage().then((res) => {
                dataSources.value = res.data;
            }).catch(() => {
                dataSources.value = [];
            }).finally(() => {
                loading.value = false;
            });
        }

        onMounted(() => {
            getPatterns();
            getData();
        });

        function handleCreate() {
            flag.value = "create";
            formInfo.value = initFormInfo();
            visible.value = true;
        }

        function handleEdit(item) {
            flag.value = "edit";
            formInfo.value = Object.assign({}, item);
            visible.value = true;
        }

        function validate() {
            const dbInfoList = dbPatterns.value[formInfo.value.dbType];
            if (!dbInfoList) {
                api.warn("请选择数据源类别");
                return false;
            }
            const missingFields = dbInfoList.filter((item) => item.needed && !formInfo.value[item.key]).map((item) => item.description);
            if (missingFields.length > 0) {
                api.warn("请输入: ".concat(missingFields.join("、")));
                return false;
            }
            return true;
        }

        function confirm() {
            if (!validate()) {
                return;
            }
            if (flag.value === "create") {
                createDataBaseSource(formInfo.value).then(() => {
                    api.success("添加成功");
                    getData();
                    visible.value = false;
                });
            } else {
                updateDataBaseSource(formInfo.value.id, formInfo.value).then(() => {
                    api.success("更新成功");
                    getData();
                    visible.value = false;
                });
            }
        }

        return (_ctx, _cache) => {
            const _component_IconButton = _sfc_main$5;
            const _component_SimpleButton = _sfc_main$6;
            const _component_Loading = _sfc_main$7;
            const _component_Empty = _sfc_main$8;
            const _component_SimpleInput = _sfc_main$9;
            const _component_SimpleSelect = _sfc_main$a;
            const _component_SimpleDialog = _sfc_main$b;
            return openBlock(), createElementBlock(Fragment, null, [
                createBaseVNode("div", _hoisted_1$3, [
                    createBaseVNode("div", _hoisted_2$3, [
                        _cache[16] || (_cache[16] = createBaseVNode("div", {class: "text-1.2rem font-600"}, " 数据源管理 ", -1)),
                        createVNode(_component_IconButton, {
                            class: "h-7 w-7",
                            "icon-class": "i-mdi:refresh",
                            title: "刷新",
                            onClick: getData
                        }),
                        !unref(loading) ? (openBlock(), createBlock(_component_SimpleButton, {
                            key: 0,
                            type: "primary",
                            class: "ml-auto h-9 gap-1",
                            onClick: handleCreate
                        }, {
                            default: withCtx(() => _cache[15] || (_cache[15] = [
                                createBaseVNode("div", {class: "i-ph:plus-bold"}, null, -1),
                                createTextVNode(" 添加数据源 ")
                            ])),
                            _: 1
                        })) : createCommentVNode("", true)
                    ]),
                    unref(loading) ? (openBlock(), createBlock(_component_Loading, {key: 0})) : unref(dataSources) && unref(dataSources).length > 0 ? (openBlock(), createElementBlock("ul", _hoisted_3$2, [
                        (openBlock(true), createElementBlock(Fragment, null, renderList(unref(dataSources), (item) => {
                            return openBlock(), createElementBlock("li", {
                                key: item.rdbName,
                                class: "flex items-center justify-between gap-4 rounded-md bg-gray-100 px-4 py-2"
                            }, [
                                createBaseVNode("div", _hoisted_4$2, [
                                    createBaseVNode("div", _hoisted_5$2, [
                                        createBaseVNode("code", {
                                            class: normalizeClass(["flex-none px-2 py-1px text-sm", typeClassMap[item.dbType] || "gray-badge"])
                                        }, toDisplayString(item.dbType) + " (" + toDisplayString(item.rwType) + ") ", 3),
                                        createBaseVNode("span", _hoisted_6$2, toDisplayString(item.rdbName), 1)
                                    ]),
                                    createBaseVNode("div", _hoisted_7$1, toDisplayString(item.dbUrl), 1),
                                    createBaseVNode("div", _hoisted_8$1, toDisplayString(item.record), 1)
                                ]),
                                createBaseVNode("div", _hoisted_9$1, [
                                    createBaseVNode("button", {
                                        class: "a-primary",
                                        onClick: ($event) => handleEdit(item)
                                    }, " 编辑 ", 8, _hoisted_10$1)
                                ])
                            ]);
                        }), 128))
                    ])) : (openBlock(), createElementBlock("div", _hoisted_11$1, [
                        createVNode(_component_Empty, {icon: "i-carbon:border-none op60 text-1.4rem"}, {
                            default: withCtx(() => _cache[17] || (_cache[17] = [
                                createBaseVNode("span", {class: "op60"}, "暂无数据源", -1)
                            ])),
                            _: 1
                        })
                    ]))
                ]),
                createVNode(_component_SimpleDialog, {
                    modelValue: unref(visible),
                    "onUpdate:modelValue": _cache[14] || (_cache[14] = ($event) => isRef(visible) ? visible.value = $event : null),
                    class: "w-500px flex flex-col"
                }, {
                    default: withCtx(() => [
                        createBaseVNode("h2", _hoisted_12$1, toDisplayString(unref(flag) === "create" ? "添加数据源" : "编辑数据源"), 1),
                        createBaseVNode("div", _hoisted_13$1, [
                            createBaseVNode("div", _hoisted_14$1, [
                                _cache[18] || (_cache[18] = createBaseVNode("label", null, [
                                    createBaseVNode("span", {"text-red-500": ""}, "*"),
                                    createTextVNode(" 数据源名称")
                                ], -1)),
                                createVNode(_component_SimpleInput, {
                                    modelValue: unref(formInfo).rdbName,
                                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => unref(formInfo).rdbName = $event),
                                    modelModifiers: {trim: true},
                                    maxlength: 64,
                                    placeholder: "请输入"
                                }, null, 8, ["modelValue"])
                            ]),
                            createBaseVNode("div", _hoisted_15$1, [
                                createBaseVNode("div", _hoisted_16$1, [
                                    _cache[19] || (_cache[19] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 数据源类别")
                                    ], -1)),
                                    createVNode(_component_SimpleSelect, {
                                        modelValue: unref(formInfo).dbType,
                                        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => unref(formInfo).dbType = $event),
                                        placeholder: "请选择"
                                    }, {
                                        default: withCtx(() => [
                                            (openBlock(true), createElementBlock(Fragment, null, renderList(unref(dbTypes), (item) => {
                                                return openBlock(), createElementBlock("option", {
                                                    key: item,
                                                    value: item
                                                }, toDisplayString(item), 9, _hoisted_17$1);
                                            }), 128))
                                        ]),
                                        _: 1
                                    }, 8, ["modelValue"])
                                ]),
                                createBaseVNode("div", _hoisted_18$1, [
                                    _cache[20] || (_cache[20] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 读写类型")
                                    ], -1)),
                                    createVNode(_component_SimpleSelect, {
                                        modelValue: unref(formInfo).rwType,
                                        "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => unref(formInfo).rwType = $event),
                                        placeholder: "请选择"
                                    }, {
                                        default: withCtx(() => [
                                            (openBlock(), createElementBlock(Fragment, null, renderList(["READ", "WRITE"], (item) => {
                                                return createBaseVNode("option", {
                                                    key: item,
                                                    value: item
                                                }, toDisplayString(item), 9, _hoisted_19$1);
                                            }), 64))
                                        ]),
                                        _: 1
                                    }, 8, ["modelValue"])
                                ])
                            ]),
                            createBaseVNode("div", _hoisted_20$1, [
                                _cache[21] || (_cache[21] = createBaseVNode("label", null, [
                                    createBaseVNode("span", {"text-red-500": ""}, "*"),
                                    createTextVNode(" 数据源链接")
                                ], -1)),
                                createVNode(_component_SimpleInput, {
                                    modelValue: unref(formInfo).dbUrl,
                                    "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => unref(formInfo).dbUrl = $event),
                                    modelModifiers: {trim: true},
                                    maxlength: 400,
                                    placeholder: "请输入"
                                }, null, 8, ["modelValue"])
                            ]),
                            createBaseVNode("div", _hoisted_21$1, [
                                createBaseVNode("div", _hoisted_22$1, [
                                    _cache[22] || (_cache[22] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 用户名")
                                    ], -1)),
                                    createVNode(_component_SimpleInput, {
                                        modelValue: unref(formInfo).dbUserName,
                                        "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => unref(formInfo).dbUserName = $event),
                                        modelModifiers: {trim: true},
                                        maxlength: 32,
                                        placeholder: "请输入"
                                    }, null, 8, ["modelValue"])
                                ]),
                                createBaseVNode("div", _hoisted_23$1, [
                                    _cache[23] || (_cache[23] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 密码")
                                    ], -1)),
                                    createVNode(_component_SimpleInput, {
                                        modelValue: unref(formInfo).dbPassword,
                                        "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => unref(formInfo).dbPassword = $event),
                                        modelModifiers: {trim: true},
                                        maxlength: 32,
                                        type: "password",
                                        placeholder: "请输入"
                                    }, null, 8, ["modelValue"])
                                ])
                            ]),
                            unref(formInfo).dbType === "clickhouse" ? (openBlock(), createElementBlock(Fragment, {key: 0}, [
                                createBaseVNode("div", _hoisted_24$1, [
                                    _cache[24] || (_cache[24] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 驱动名称")
                                    ], -1)),
                                    createVNode(_component_SimpleInput, {
                                        modelValue: unref(formInfo).driverName,
                                        "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => unref(formInfo).driverName = $event),
                                        modelModifiers: {trim: true},
                                        maxlength: 256,
                                        placeholder: "请输入"
                                    }, null, 8, ["modelValue"])
                                ]),
                                createBaseVNode("div", _hoisted_25$1, [
                                    _cache[25] || (_cache[25] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 库名称")
                                    ], -1)),
                                    createVNode(_component_SimpleInput, {
                                        modelValue: unref(formInfo).schemaName,
                                        "onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => unref(formInfo).schemaName = $event),
                                        modelModifiers: {trim: true},
                                        maxlength: 256,
                                        placeholder: "请输入"
                                    }, null, 8, ["modelValue"])
                                ]),
                                createBaseVNode("div", _hoisted_26, [
                                    _cache[26] || (_cache[26] = createBaseVNode("label", null, "集群名称", -1)),
                                    createVNode(_component_SimpleInput, {
                                        modelValue: unref(formInfo).clusterName,
                                        "onUpdate:modelValue": _cache[8] || (_cache[8] = ($event) => unref(formInfo).clusterName = $event),
                                        modelModifiers: {trim: true},
                                        maxlength: 400,
                                        placeholder: "请输入"
                                    }, null, 8, ["modelValue"])
                                ]),
                                createBaseVNode("div", _hoisted_27, [
                                    _cache[27] || (_cache[27] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 存储引擎")
                                    ], -1)),
                                    createVNode(_component_SimpleInput, {
                                        modelValue: unref(formInfo).engine,
                                        "onUpdate:modelValue": _cache[9] || (_cache[9] = ($event) => unref(formInfo).engine = $event),
                                        modelModifiers: {trim: true},
                                        maxlength: 400,
                                        placeholder: "请输入"
                                    }, null, 8, ["modelValue"])
                                ])
                            ], 64)) : createCommentVNode("", true),
                            unref(formInfo).dbType === "dm" ? (openBlock(), createElementBlock(Fragment, {key: 1}, [
                                createBaseVNode("div", _hoisted_28, [
                                    _cache[28] || (_cache[28] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 驱动名称")
                                    ], -1)),
                                    createVNode(_component_SimpleInput, {
                                        modelValue: unref(formInfo).driverName,
                                        "onUpdate:modelValue": _cache[10] || (_cache[10] = ($event) => unref(formInfo).driverName = $event),
                                        modelModifiers: {trim: true},
                                        maxlength: 256,
                                        placeholder: "请输入"
                                    }, null, 8, ["modelValue"])
                                ]),
                                createBaseVNode("div", _hoisted_29, [
                                    _cache[29] || (_cache[29] = createBaseVNode("label", null, [
                                        createBaseVNode("span", {"text-red-500": ""}, "*"),
                                        createTextVNode(" 模式名称")
                                    ], -1)),
                                    createVNode(_component_SimpleInput, {
                                        modelValue: unref(formInfo).schemaName,
                                        "onUpdate:modelValue": _cache[11] || (_cache[11] = ($event) => unref(formInfo).schemaName = $event),
                                        modelModifiers: {trim: true},
                                        maxlength: 256,
                                        placeholder: "请输入"
                                    }, null, 8, ["modelValue"])
                                ])
                            ], 64)) : createCommentVNode("", true),
                            createBaseVNode("div", _hoisted_30, [
                                _cache[30] || (_cache[30] = createBaseVNode("label", null, "备注", -1)),
                                createVNode(_component_SimpleInput, {
                                    modelValue: unref(formInfo).record,
                                    "onUpdate:modelValue": _cache[12] || (_cache[12] = ($event) => unref(formInfo).record = $event),
                                    modelModifiers: {trim: true},
                                    maxlength: 512,
                                    placeholder: "请输入"
                                }, null, 8, ["modelValue"])
                            ])
                        ]),
                        createBaseVNode("div", _hoisted_31, [
                            createVNode(_component_SimpleButton, {
                                onClick: _cache[13] || (_cache[13] = ($event) => visible.value = false)
                            }, {
                                default: withCtx(() => _cache[31] || (_cache[31] = [
                                    createTextVNode(" 取消 ")
                                ])),
                                _: 1
                            }),
                            createVNode(_component_SimpleButton, {
                                type: "primary",
                                onClick: confirm
                            }, {
                                default: withCtx(() => _cache[32] || (_cache[32] = [
                                    createTextVNode(" 确定 ")
                                ])),
                                _: 1
                            })
                        ])
                    ]),
                    _: 1
                }, 8, ["modelValue"])
            ], 64);
        };
    }
});
const _hoisted_1$2 = {class: "flex flex-col gap-6 px-2"};
const _hoisted_2$2 = {class: "flex items-center gap-2"};
const _hoisted_3$1 = {
    key: 1,
    class: "flex flex-col gap-2"
};
const _hoisted_4$1 = {class: "font-500"};
const _hoisted_5$1 = {class: "flex flex-col gap-2 px-3 py-2"};
const _hoisted_6$1 = {class: "text-sm font-[monaco]"};
const _hoisted_7 = {class: "text-sm"};
const _hoisted_8 = {class: "flex-center gap-2"};
const _hoisted_9 = ["onClick"];
const _hoisted_10 = {
    key: 0,
    class: "flex flex-col gap-2"
};
const _hoisted_11 = {class: "flex flex-col gap-1 text-sm"};
const _hoisted_12 = {class: "font-500 font-[monaco]"};
const _hoisted_13 = {
    key: 0,
    class: "text-gray-600"
};
const _hoisted_14 = ["onClick"];
const _hoisted_15 = {
    key: 2,
    class: "flex-center"
};
const _hoisted_16 = {class: "flex flex-col gap-3"};
const _hoisted_17 = {class: "form-group"};
const _hoisted_18 = {class: "form-group"};
const _hoisted_19 = {class: "form-group"};
const _hoisted_20 = {class: "mt-4 flex justify-end gap-4"};
const _hoisted_21 = {class: "text-1.2rem font-600"};
const _hoisted_22 = {class: "flex flex-col gap-3"};
const _hoisted_23 = {class: "form-group"};
const _hoisted_24 = {class: "form-group"};
const _hoisted_25 = {class: "mt-4 flex justify-end gap-4"};
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
    __name: "executor",
    setup(__props) {
        const executors = ref([]);
        const eVisible = ref(false);
        const eFormInfo = ref({name: "", fileName: "", record: ""});
        const loading = ref(false);

        function getData() {
            loading.value = true;
            getExecutorList().then((res) => {
                executors.value = res.data;
            }).finally(() => {
                loading.value = false;
            });
        }

        onMounted(() => {
            getData();
        });

        function addExecutor() {
            createExecutorJar(eFormInfo.value).then(() => {
                api.success("添加成功");
                eVisible.value = false;
                getData();
            });
        }

        const epVisible = ref(false);
        const epFormInfo = ref({executorName: "", description: "", tag: "", executorJarId: ""});

        function handleAddExecutorProgram(eId) {
            epFormInfo.value.executorJarId = eId;
            epVisible.value = true;
        }

        function getExecutorPrograms(eId) {
            const executor = executors.value.find((e) => e.id === eId);
            if (!executor)
                return;
            const params = {
                executorJarId: eId
            };
            getExecutorProgramList(params).then((res) => {
                executor.executorPrograms = res.data;
            }).catch(() => {
                executor.executorPrograms = [];
            });
        }

        function addExecutorProgram() {
            const eId = epFormInfo.value.executorJarId;
            createExecutorProgram(epFormInfo.value).then(() => {
                api.success("添加成功");
                epVisible.value = false;
                getExecutorPrograms(eId);
            });
        }

        function removeExecutorProgram(eId, epId) {
            deleteExecutorProgram(epId).then(() => {
                api.success("删除成功");
                getExecutorPrograms(eId);
            });
        }

        return (_ctx, _cache) => {
            const _component_IconButton = _sfc_main$5;
            const _component_SimpleButton = _sfc_main$6;
            const _component_Loading = _sfc_main$7;
            const _component_Empty = _sfc_main$8;
            const _component_SimpleCollapse = _sfc_main$c;
            const _component_SimpleInput = _sfc_main$9;
            const _component_SimpleDialog = _sfc_main$b;
            return openBlock(), createElementBlock(Fragment, null, [
                createBaseVNode("div", _hoisted_1$2, [
                    createBaseVNode("div", _hoisted_2$2, [
                        _cache[11] || (_cache[11] = createBaseVNode("div", {class: "text-1.2rem font-600"}, " 模型执行器管理 ", -1)),
                        createVNode(_component_IconButton, {
                            class: "h-7 w-7",
                            "icon-class": "i-mdi:refresh",
                            title: "刷新",
                            onClick: getData
                        }),
                        !unref(loading) ? (openBlock(), createBlock(_component_SimpleButton, {
                            key: 0,
                            type: "primary",
                            class: "ml-auto h-9 gap-1",
                            onClick: _cache[0] || (_cache[0] = ($event) => eVisible.value = true)
                        }, {
                            default: withCtx(() => _cache[10] || (_cache[10] = [
                                createBaseVNode("div", {class: "i-ph:plus-bold"}, null, -1),
                                createTextVNode(" 添加执行器 ")
                            ])),
                            _: 1
                        })) : createCommentVNode("", true)
                    ]),
                    unref(loading) ? (openBlock(), createBlock(_component_Loading, {key: 0})) : unref(executors) && unref(executors).length > 0 ? (openBlock(), createElementBlock("div", _hoisted_3$1, [
                        (openBlock(true), createElementBlock(Fragment, null, renderList(unref(executors), (e) => {
                            return openBlock(), createBlock(_component_SimpleCollapse, {
                                key: e.id,
                                onShow: ($event) => getExecutorPrograms(e.id)
                            }, {
                                title: withCtx(() => [
                                    createBaseVNode("span", _hoisted_4$1, toDisplayString(e.name), 1)
                                ]),
                                default: withCtx(() => [
                                    createBaseVNode("div", _hoisted_5$1, [
                                        createBaseVNode("span", _hoisted_6$1, "文件名：" + toDisplayString(e.fileName), 1),
                                        createBaseVNode("span", _hoisted_7, "备注：" + toDisplayString(e.record), 1),
                                        createBaseVNode("div", _hoisted_8, [
                                            createBaseVNode("button", {
                                                class: "a-primary",
                                                onClick: ($event) => handleAddExecutorProgram(e.id)
                                            }, " 添加执行程序 ", 8, _hoisted_9),
                                            createVNode(_component_SimpleButton, {
                                                type: "soft",
                                                size: "mini",
                                                onClick: ($event) => getExecutorPrograms(e.id)
                                            }, {
                                                default: withCtx(() => _cache[12] || (_cache[12] = [
                                                    createBaseVNode("div", {class: "i-mdi:refresh"}, null, -1)
                                                ])),
                                                _: 2
                                            }, 1032, ["onClick"])
                                        ]),
                                        e.executorPrograms && e.executorPrograms.length > 0 ? (openBlock(), createElementBlock("ul", _hoisted_10, [
                                            (openBlock(true), createElementBlock(Fragment, null, renderList(e.executorPrograms, (p) => {
                                                return openBlock(), createElementBlock("li", {
                                                    key: p.id,
                                                    class: "flex items-center justify-between rounded-md bg-gray-100 px-4 py-2"
                                                }, [
                                                    createBaseVNode("div", _hoisted_11, [
                                                        createBaseVNode("span", _hoisted_12, toDisplayString(p.executorName), 1),
                                                        p.description ? (openBlock(), createElementBlock("div", _hoisted_13, toDisplayString(p.description), 1)) : createCommentVNode("", true)
                                                    ]),
                                                    createBaseVNode("button", {
                                                        class: "text-sm a-error",
                                                        onClick: ($event) => removeExecutorProgram(e.id, p.id)
                                                    }, " 删除 ", 8, _hoisted_14)
                                                ]);
                                            }), 128))
                                        ])) : (openBlock(), createBlock(_component_Empty, {key: 1}, {
                                            default: withCtx(() => _cache[13] || (_cache[13] = [
                                                createBaseVNode("span", {class: "op60"}, "暂无执行程序", -1)
                                            ])),
                                            _: 1
                                        }))
                                    ])
                                ]),
                                _: 2
                            }, 1032, ["onShow"]);
                        }), 128))
                    ])) : (openBlock(), createElementBlock("div", _hoisted_15, [
                        createVNode(_component_Empty, {icon: "i-carbon:border-none op60 text-1.4rem"}, {
                            default: withCtx(() => _cache[14] || (_cache[14] = [
                                createBaseVNode("span", {class: "op60"}, "暂无执行器", -1)
                            ])),
                            _: 1
                        })
                    ]))
                ]),
                createVNode(_component_SimpleDialog, {
                    modelValue: unref(eVisible),
                    "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => isRef(eVisible) ? eVisible.value = $event : null),
                    "not-close-on-click": "",
                    class: "flex flex-col gap-6 p-6 !w-400px"
                }, {
                    default: withCtx(() => [
                        _cache[20] || (_cache[20] = createBaseVNode("h2", {class: "text-1.2rem font-600"}, " 添加执行器 ", -1)),
                        createBaseVNode("div", _hoisted_16, [
                            createBaseVNode("div", _hoisted_17, [
                                _cache[15] || (_cache[15] = createBaseVNode("label", null, [
                                    createBaseVNode("span", {"text-red-500": ""}, "*"),
                                    createTextVNode(" 执行器名称")
                                ], -1)),
                                createVNode(_component_SimpleInput, {
                                    modelValue: unref(eFormInfo).name,
                                    "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => unref(eFormInfo).name = $event),
                                    modelModifiers: {trim: true},
                                    maxlength: 64,
                                    placeholder: "请输入"
                                }, null, 8, ["modelValue"])
                            ]),
                            createBaseVNode("div", _hoisted_18, [
                                _cache[16] || (_cache[16] = createBaseVNode("label", null, [
                                    createBaseVNode("span", {"text-red-500": ""}, "*"),
                                    createTextVNode(" 执行器文件名")
                                ], -1)),
                                createVNode(_component_SimpleInput, {
                                    modelValue: unref(eFormInfo).fileName,
                                    "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => unref(eFormInfo).fileName = $event),
                                    modelModifiers: {trim: true},
                                    maxlength: 256,
                                    placeholder: "请输入"
                                }, null, 8, ["modelValue"])
                            ]),
                            createBaseVNode("div", _hoisted_19, [
                                _cache[17] || (_cache[17] = createBaseVNode("label", null, "备注", -1)),
                                createVNode(_component_SimpleInput, {
                                    modelValue: unref(eFormInfo).record,
                                    "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => unref(eFormInfo).record = $event),
                                    modelModifiers: {trim: true},
                                    maxlength: 256,
                                    placeholder: "请输入"
                                }, null, 8, ["modelValue"])
                            ]),
                            createBaseVNode("div", _hoisted_20, [
                                createVNode(_component_SimpleButton, {
                                    onClick: _cache[4] || (_cache[4] = ($event) => eVisible.value = false)
                                }, {
                                    default: withCtx(() => _cache[18] || (_cache[18] = [
                                        createTextVNode(" 取消 ")
                                    ])),
                                    _: 1
                                }),
                                createVNode(_component_SimpleButton, {
                                    type: "primary",
                                    onClick: addExecutor
                                }, {
                                    default: withCtx(() => _cache[19] || (_cache[19] = [
                                        createTextVNode(" 确定 ")
                                    ])),
                                    _: 1
                                })
                            ])
                        ])
                    ]),
                    _: 1
                }, 8, ["modelValue"]),
                createVNode(_component_SimpleDialog, {
                    modelValue: unref(epVisible),
                    "onUpdate:modelValue": _cache[9] || (_cache[9] = ($event) => isRef(epVisible) ? epVisible.value = $event : null),
                    "not-close-on-click": "",
                    class: "flex flex-col gap-6 p-6 !w-400px"
                }, {
                    default: withCtx(() => [
                        createBaseVNode("h2", _hoisted_21, " 添加执行程序（所属执行器：" + toDisplayString(unref(epFormInfo).executorJarId) + "） ", 1),
                        createBaseVNode("div", _hoisted_22, [
                            createBaseVNode("div", _hoisted_23, [
                                _cache[21] || (_cache[21] = createBaseVNode("label", null, [
                                    createBaseVNode("span", {"text-red-500": ""}, "*"),
                                    createTextVNode(" 执行程序名称")
                                ], -1)),
                                createVNode(_component_SimpleInput, {
                                    modelValue: unref(epFormInfo).executorName,
                                    "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => unref(epFormInfo).executorName = $event),
                                    modelModifiers: {trim: true},
                                    maxlength: 64,
                                    placeholder: "请输入"
                                }, null, 8, ["modelValue"])
                            ]),
                            createBaseVNode("div", _hoisted_24, [
                                _cache[22] || (_cache[22] = createBaseVNode("label", null, "描述", -1)),
                                createVNode(_component_SimpleInput, {
                                    modelValue: unref(epFormInfo).description,
                                    "onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => unref(epFormInfo).description = $event),
                                    modelModifiers: {trim: true},
                                    maxlength: 256,
                                    placeholder: "请输入"
                                }, null, 8, ["modelValue"])
                            ]),
                            createBaseVNode("div", _hoisted_25, [
                                createVNode(_component_SimpleButton, {
                                    onClick: _cache[8] || (_cache[8] = ($event) => epVisible.value = false)
                                }, {
                                    default: withCtx(() => _cache[23] || (_cache[23] = [
                                        createTextVNode(" 取消 ")
                                    ])),
                                    _: 1
                                }),
                                createVNode(_component_SimpleButton, {
                                    type: "primary",
                                    onClick: addExecutorProgram
                                }, {
                                    default: withCtx(() => _cache[24] || (_cache[24] = [
                                        createTextVNode(" 确定 ")
                                    ])),
                                    _: 1
                                })
                            ])
                        ])
                    ]),
                    _: 1
                }, 8, ["modelValue"])
            ], 64);
        };
    }
});
const _hoisted_1$1 = {class: "flex flex-col gap-6 px-2"};
const _hoisted_2$1 = {class: "flex items-center gap-2"};
const _hoisted_3 = {class: "flex items-center gap-4"};
const _hoisted_4 = {
    key: 1,
    class: "flex flex-wrap gap-2"
};
const _hoisted_5 = {class: "color-gray-600"};
const _hoisted_6 = {
    key: 2,
    class: "flex-center"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
    __name: "tag",
    setup(__props) {
        const tags = ref([]);
        const newTag = ref("");
        const loading = ref(false);

        function getData() {
            loading.value = true;
            getAllTags().then((res) => {
                tags.value = res.data;
            }).catch(() => {
                tags.value = [];
            }).finally(() => {
                loading.value = false;
            });
        }

        onMounted(() => {
            getData();
        });

        function addTag() {
            const val = newTag.value.trim();
            if (!val) {
                api.warning("请输入标签名称");
                return;
            }
            if (val.length > 32) {
                api.warning("标签名称长度不能超过 32 个字符");
                return;
            }
            if (!/^[a-z\u4E00-\u9FA50-9]+$/i.test(val)) {
                api.warning("标签名称只能包含字母、中文、数字");
                return;
            }
            if (tags.value.some((t) => t.tagName === val)) {
                api.warning("标签名称已存在");
                return;
            }
            createTag({tagName: val}).then(() => {
                getData();
                newTag.value = "";
            });
        }

        function removeTag(tagId) {
            deleteTag(tagId).then(() => {
                getData();
            });
        }

        return (_ctx, _cache) => {
            const _component_IconButton = _sfc_main$5;
            const _component_SimpleInput = _sfc_main$9;
            const _component_SimpleButton = _sfc_main$6;
            const _component_Loading = _sfc_main$7;
            const _component_Empty = _sfc_main$8;
            return openBlock(), createElementBlock("div", _hoisted_1$1, [
                createBaseVNode("div", _hoisted_2$1, [
                    _cache[1] || (_cache[1] = createBaseVNode("div", {class: "text-1.2rem font-600"}, " 模型标签管理 ", -1)),
                    createVNode(_component_IconButton, {
                        class: "h-7 w-7",
                        "icon-class": "i-mdi:refresh",
                        title: "刷新",
                        onClick: getData
                    })
                ]),
                createBaseVNode("div", _hoisted_3, [
                    createVNode(_component_SimpleInput, {
                        modelValue: unref(newTag),
                        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(newTag) ? newTag.value = $event : null),
                        maxlength: 32,
                        class: "w-60",
                        placeholder: "输入新标签",
                        onKeyup: withKeys(addTag, ["enter"])
                    }, null, 8, ["modelValue"]),
                    createVNode(_component_SimpleButton, {
                        type: "primary",
                        class: "gap-1",
                        onClick: addTag
                    }, {
                        default: withCtx(() => _cache[2] || (_cache[2] = [
                            createBaseVNode("div", {class: "i-ph:plus-bold"}, null, -1),
                            createTextVNode(" 添加 ")
                        ])),
                        _: 1
                    })
                ]),
                unref(loading) ? (openBlock(), createBlock(_component_Loading, {key: 0})) : unref(tags) && unref(tags).length > 0 ? (openBlock(), createElementBlock("ul", _hoisted_4, [
                    (openBlock(true), createElementBlock(Fragment, null, renderList(unref(tags), (item) => {
                        return openBlock(), createElementBlock("li", {
                            key: item.id,
                            class: "flex items-center gap-2 rounded-md bg-gray-100 py-1 pl-3 pr-2 text-0.9rem"
                        }, [
                            createBaseVNode("span", _hoisted_5, toDisplayString(item.tagName), 1),
                            createVNode(_component_IconButton, {
                                class: "!h-4.5 !w-4.5",
                                "icon-class": "i-carbon:close text-red",
                                onClick: ($event) => removeTag(item.id)
                            }, null, 8, ["onClick"])
                        ]);
                    }), 128))
                ])) : (openBlock(), createElementBlock("div", _hoisted_6, [
                    createVNode(_component_Empty, {icon: "i-carbon:border-none op60 text-1.4rem"}, {
                        default: withCtx(() => _cache[3] || (_cache[3] = [
                            createBaseVNode("span", {class: "op60"}, "暂无标签", -1)
                        ])),
                        _: 1
                    })
                ]))
            ]);
        };
    }
});
const _hoisted_1 = {class: "h-full w-full overflow-y-overlay p-4"};
const _hoisted_2 = {class: "mx-auto w-60% flex flex-col gap-6 rounded-lg bg-base p-8"};
const _sfc_main = /* @__PURE__ */ defineComponent({
    __name: "index",
    setup(__props) {
        const tabs = [
            {label: "数据源管理", value: "data-source", icon: "i-ph:database-duotone text-1.1rem mr-1"},
            {label: "模型执行器管理", value: "executor", icon: "i-ph:fast-forward-duotone text-1.1rem mr-1"},
            {label: "模型标签管理", value: "tag", icon: "i-ph:tag-duotone text-1.1rem mr-1"}
        ];
        const {activeTab} = useUrlQuery(tabs);
        return (_ctx, _cache) => {
            const _component_SimpleTabs = _sfc_main$4;
            return openBlock(), createElementBlock("div", _hoisted_1, [
                createBaseVNode("div", _hoisted_2, [
                    createVNode(_component_SimpleTabs, {
                        modelValue: unref(activeTab),
                        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(activeTab) ? activeTab.value = $event : null),
                        options: tabs,
                        blocked: ""
                    }, null, 8, ["modelValue"]),
                    unref(activeTab) === "data-source" ? (openBlock(), createBlock(_sfc_main$3, {key: 0})) : createCommentVNode("", true),
                    unref(activeTab) === "executor" ? (openBlock(), createBlock(_sfc_main$2, {key: 1})) : createCommentVNode("", true),
                    unref(activeTab) === "tag" ? (openBlock(), createBlock(_sfc_main$1, {key: 2})) : createCommentVNode("", true)
                ])
            ]);
        };
    }
});
export {
    _sfc_main as default
};
